import pytest

# 全局event
from api_test.api.calendar.event_api import EventApi


@pytest.fixture(name="event", scope="package")
def init_event(calendar):
    print("setup_module")
    event = EventApi()
    yield event
    print(f"\nteardown_module {event.event_ids}")
    for cid in calendar.calendar_ids:
        for eid in event.event_ids:
            res = event.delete(cid, eid)
            if res.get('code') != 0:
                if res.get('code') != 193003:
                    print(f"\n{eid} 删除失败 {res}")
                    return f"\n{eid} 删除失败 {res}"
        res = calendar.delete(cid)
        print(f"calendarapi.delete: {res}")
        if res.get('code') != 0:
            if res.get('code') != 191003:
                print(f"\n{cid} 删除失败 {res}")
                return f"\n{cid} 删除失败 {res}"
    print("\n数据后置OK! ")
